﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class WinPanel : PanelBase
{
    private Button restartButton;
    private Button closeButton;
    private Animator animator;

    #region 生命周期
    public override void Init(params object[] args)
    {
        skin = this.gameObject;
        base.Init(args);
        skinPath = "UI/Prefabs/WinPanel";//定义皮肤skinPath
        layer = PanelMgr.PanelLayer.Panel;//定义层级layer
    }
    public override void OnShowing()
    {
        base.OnShowing();
        PanelMgr.Instance.OpenPanel<WinPanel>(skinPath);
        PanelMgr.Instance.ClosePanel("GamePanel");

        animator = skin.transform.GetComponent<Animator>();
        restartButton = skin.transform.Find("RestartButton").GetComponent<Button>();
        closeButton = skin.transform.Find("CloseButton").GetComponent<Button>();

        restartButton.onClick.AddListener(delegate ()
        {
            SceneManager.LoadScene(0);
        });
        closeButton.onClick.AddListener(delegate ()
        {
            Application.Quit();
        });
        
    }
    public override void Update()
    {
        base.Update();
        if (animator != null)
        {
            AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
            if (info.normalizedTime >= 1.0f)
            {
                Time.timeScale = 0;
            }
        }
    }
    public override void OnClosing()
    {
        base.OnClosing();
        Close();
    }
    #endregion

    // 关闭按钮监听函数
    private void OnCloseClick()
    {
        OnClosing();
    }
}
